package cn.heygod.airsql.meta;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @className: TableMetadata
 * @author: Simon
 * @description: TODO
 * @date: 2024/1/31 4:21
 * @version: 1.0
 */
public class TableMetadata {

    private final String tableName;

    /**
     * Key:Field
     * Value:Column
     */
    private Map<String,String> fieldMapped = new HashMap<>();
    /**
     * Key:Column
     * Value:Field
     */
    private Map<String,String> columnMapped = new HashMap<>();

    private Set<ColumnMetadata> columnsMetaSet = new HashSet<>();


    public TableMetadata(String tableName, ColumnMetadata[] columnMetadataArray) {
        this.tableName = tableName;
        for (ColumnMetadata columnMetadata : columnMetadataArray ) {
           fieldMapped.put(columnMetadata.getFieldName(),columnMetadata.getColumnName());
           columnMapped.put(columnMetadata.getColumnName(),columnMetadata.getFieldName());
           columnsMetaSet.add(columnMetadata);
        }
    }

    public String getTableName() {
        return tableName;
    }

    public String  getColumn(String field) {
        return fieldMapped.get(field);
    }

    public String  getField(String column) {
        return columnMapped.get(column);
    }

    public Set<String> getFields(){
        return fieldMapped.keySet();
    }


    public Set<String> getColumns(){
        return columnMapped.keySet();
    }

    public Set<ColumnMetadata> getColumnsMetas(){
        return this.columnsMetaSet;
    }


}
